/*
 * @Author: EternityJun 2438965023@qq.com
 * @Date: 2025-05-14 10:17:03
 * @LastEditors: EternityJun 2438965023@qq.com
 * @LastEditTime: 2025-05-19 14:14:09
 * @FilePath: \private-domain-small-program\src\utils\isLogin.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useAccessStore } from '@/store'
export function isGoLogin() {
  const accessStore = useAccessStore()
  const token = accessStore?.accessToken as unknown as IUserInfo
  console.log(token, '======token')
  if (!token) {
    // 已登录跳转主页
    uni.reLaunch({
      url: '/pages-sub/login/index',
    })
  }
}
// 处理
export function autoUnit(num) {
  num = num / 100
  const units = [
    { value: 1e8, symbol: '亿' },
    { value: 1e4, symbol: '万' },
  ]

  for (const unit of units) {
    if (num >= unit.value) {
      return (num / unit.value).toFixed(1) + unit.symbol
    }
  }
  return num.toString()
}

export const copy = async (text) => {
  uni.setClipboardData({
    data: text,
    success: () => {
      uni.showToast({
        title: '复制成功',
        icon: 'none',
      })
    },
    fail: (err) => {
      console.error('复制失败:', err)
      uni.showToast({
        title: '复制失败',
        icon: 'none',
      })
    },
  })
}

export const openBusinessView = () => {
    let bind_status = Number(uni.getStorageSync('bind_status'));
  if (bind_status == 0) {
    wx.openBusinessView(
      {
        businessType: 'CreatorApplyments',
        register_status: 0,
        queryString: 'redirect_url=%2Fauth%2Fpages%2Fauthorization%2Findex&is_simple_register=1&is_from_promoter=1',
        extraData: {
          commissionType: 1,
          commissionRatio: 0,
          headSupplierAppid: 'wx36fa56f8cb04e3c9'
        }
      })
  }
}